//
//  CommonObj.cpp
//  NinjaTurtle
//
//  Created by Nguyen Tri Chung on 2/3/15.
//
//

#include "CommonObj.h"

CommonObj::CommonObj() {
    this->valueString = "";
}

void CommonObj::initWithFrame(const string& frame) {
    CSprite* mainFace = new CSprite(SPRITE_TYPE_MAIN);
    mainFace->initWithSpriteFrameName(frame);
    this->sprites->pushBack(mainFace);
    
    RectBody* body = new RectBody(mainFace->getContentSize().width, mainFace->getContentSize().height);
    CC_SAFE_RETAIN(body);
    this->body = body;
}

CommonObj::CommonObj(const string& identifier) {
    this->valueString = "";
    CSprite* mainFace = new CSprite(SPRITE_TYPE_MAIN);
    mainFace->initWithIdentifier(identifier);
    this->sprites->pushBack(mainFace);
    
    RectBody* body = new RectBody(mainFace->getContentSize().width, mainFace->getContentSize().height);
    CC_SAFE_RETAIN(body);
    this->body = body;
}

CommonObj::CommonObj(const string& identifier, const string& animation) {
    this->valueString = "";
    CSprite* mainFace = new CSprite(SPRITE_TYPE_MAIN);
    mainFace->initWithIdentifier(identifier);
    mainFace->bind(CStringUtil::getPattern(animation));
    this->sprites->pushBack(mainFace);
    
    RectBody* body = new RectBody(mainFace->getContentSize().width, mainFace->getContentSize().height);
    CC_SAFE_RETAIN(body);
    this->body = body;
}

CommonObj::CommonObj(const string& identifier, const vector<string>& animations) {
    this->valueString = "";
    CSprite* mainFace = new CSprite(SPRITE_TYPE_MAIN);
    mainFace->initWithIdentifier(identifier);
    for (auto animation = animations.begin(); animation < animations.end(); animation++) {
        string animationIdentifier = *animation;
        mainFace->bind(CStringUtil::getPattern(animationIdentifier));
    }
    this->sprites->pushBack(mainFace);    
    
    RectBody* body = new RectBody(mainFace->getContentSize().width, mainFace->getContentSize().height);
    CC_SAFE_RETAIN(body);
    this->body = body;
}

CommonObj::~CommonObj() {
}